import React, { Component } from 'react';
import autoBind from 'react-autobind';
import { Link, browserHistory } from 'dva/router';
import { NavBar } from 'antd-mobile';

// style
import styles from './index.css';
import IconfontStyle from '../../../assets/iconfont/iconfont.css';

class HeadNav extends Component {
	constructor(props) {
        super(props)
        autoBind(this)

        this.state = {
        }
    }

    onClickBack() {
    	const { leftPath } = this.props

    	if(leftPath) {
    		browserHistory.push(leftPath)
    	} else {
    		browserHistory.goBack()
    	}
    }
	render() {
		const { title, noLeftIcon, leftPath } = this.props

	 	return (
	 		<div className="head-nav">
	 			{
	 				noLeftIcon ? (
	 					<NavBar mode="dark" 
			 				iconName={null}
					      	rightContent={null}
					    >
					    	{title} 
					    </NavBar>) : (
	 					<NavBar mode="dark" 
			 				iconName={null}
			 				leftContent={[<i key={0} onClick={this.onClickBack} className={`${IconfontStyle['meyley-icon']} ${IconfontStyle['meyley-icon-left-arrow']}`} style={{fontSize: '0.4rem', color: 'rgb(66, 62, 62)', position: 'relative', bottom: 4}}/>]} 
					      	rightContent={null}
					    >
					    	{title}
					    </NavBar>)
	 			}
	 		</div>
	  	);
	}
};

HeadNav.propTypes = {
};

export default HeadNav
